package net.xfok.info.tech;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.http.HttpException;

import android.util.Log;

/**
 * @author YangHua
 *
 */
public class InfoRequest {
	private String TAG = "HttpDataRequest";
	private String mHostString;

	/**
	 * construct with URL input parameter
	 * 
	 * @param url
	 * @throws HttpException
	 */
	public InfoRequest(String hostString,String port){
		try{
			this.mHostString = hostString;
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * get input stream from http connection
	 * 
	 * @return http input stream
	 * @throws IOException 
	 */
	public InputStream doPost(){
		InputStream inputStream = null;
		/*
		 *  Open connection
		 */
		try{
			URL url = new URL(mHostString.replace(" ", "%20"));
			HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
			try{
				int responseCode = urlConnection.getResponseCode();
				if (responseCode == HttpURLConnection.HTTP_OK) {
					inputStream = urlConnection.getInputStream();
				} else {
					inputStream = null;;
				}
			}catch(Exception e){
				e.printStackTrace();
			}	
		}catch(Exception e){
			e.printStackTrace();
		}
		return inputStream;
	}
}